# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Jonahtan Schaeffer <joschaeffer@gmail.com>
# COntributor: Drake Arconis <lightdrake@gmail.com>

pkgbase=jsoncpp
pkgname=('jsoncpp' 'jsoncpp-doc')
pkgver=1.8.4
pkgrel=2
pkgdesc='C++ library for interacting with JSON'
url='https://github.com/open-source-parsers/jsoncpp'
arch=('x86_64')
license=('MIT' 'custom:Public_Domain')
makedepends=('gcc-libs' 'doxygen' 'graphviz' 'python' 'meson')
checkdepends=('python2')
options=('staticlibs')
source=(${pkgbase}-${pkgver}.tar.gz::https://github.com/open-source-parsers/${pkgbase}/archive/${pkgver}.tar.gz)
sha256sums=('c49deac9e0933bcb7044f08516861a2d560988540b23de2ac1ad443b219afdb6')
sha512sums=('f70361a3263dd8b9441374a9a409462be1426c0d6587c865171a80448ab73b3f69de2b4d70d2f0c541764e1e6cccc727dd53178347901f625ec6fb54fb94f4f1')

prepare() {
  cd ${pkgbase}-${pkgver}
  mkdir -p build
}

build() {
  cd ${pkgbase}-${pkgver}
  msg2 "Building docs..."
  python doxybuild.py \
    --doxygen="$(which doxygen)" \
    --with-dot

  msg2 "Building shared library..."
  arch-meson --default-library shared build
  ninja -C build

  msg2 "Building static library..."
  arch-meson --default-library static build-static
  ninja -C build-static
}

check() {
  cd ${pkgbase}-${pkgver}
  ninja -C build test
  cd test
  python2 runjsontests.py ../build/jsontestrunner
  python2 rununittests.py ../build/jsoncpp_test
}

package_jsoncpp() {
  depends=('gcc-libs')
  optdepends=('jsoncpp-doc: documentation')

  cd ${pkgbase}-${pkgver}
  DESTDIR="${pkgdir}" ninja -C build install
  DESTDIR="${pkgdir}" ninja -C build-static install
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
}

package_jsoncpp-doc() {
  pkgdesc+=' (documentation)'
  optdepends=('jsoncpp')

  cd ${pkgbase}-${pkgver}
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -dm 755 "${pkgdir}/usr/share/doc/${pkgbase}"
  cp -a dist/doxygen/jsoncpp-api-html-${pkgver} "${pkgdir}/usr/share/doc/${pkgbase}/html"
}

# vim: ts=2 sw=2 et:
